<template>
    <!-- 首页视图文件 -->
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20">
                    <div class="user-info">
                        <img src="../../assets/img/img.jpg" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">{{ name }}</div>
                            <div>{{ role }}</div>
                        </div>
                    </div>
                </el-card>
                <el-card shadow="hover" style="height:410px;">
                    <div slot="header" class="clearfix">
                        <span>数据统计占比</span>
                    </div>
                    男生占比
                    <el-progress
                        :percentage="(man_count / user_count) * 100"
                        color="#42b983"
                        v-if="!isNaN(parseInt((eight_count / user_count) * 100))"
                    ></el-progress>
                    女生占比
                    <el-progress
                        :percentage="(wuman_count / user_count) * 100"
                        color="#42b983"
                        v-if="!isNaN(parseInt((eight_count / user_count) * 100))"
                    ></el-progress>
                    年龄统计（18-24）<el-progress
                        :percentage="(eight_count / user_count) * 100"
                        color="#f1e05a"
                        v-if="!isNaN(parseInt((eight_count / user_count) * 100))"
                    ></el-progress>
                    年龄统计（24-30）<el-progress :percentage="0"></el-progress> 少数民族占比<el-progress
                        :percentage="0"
                        color="#f56c6c"
                    ></el-progress>
                </el-card>
            </el-col>
            <el-col :span="16">
                <el-row :gutter="20" class="mgb20">
                    <el-calendar v-model="value"> </el-calendar>
                </el-row>
            </el-col>
        </el-row>
        <el-row>
            <el-col>
                <el-card shadow="hover">
                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import Schart from 'vue-schart';
import bus from '../../components/common/bus';
export default {
    name: 'dashboard',
    data() {
        return {
            // 总人数
            user_count: 0,
            // 男生总人数
            man_count: 0,
            // 女生总人数
            wuman_count: 0,
            // 18-24之间的人数
            eight_count: 0,
            name: JSON.parse(localStorage.getItem('student')).name,
            data: [],
            value: new Date(),
            options2: {
                type: 'line',
                title: {
                    text: '新生报到可视化数据图'
                },
                labels: ['四川', '北京', '江苏', '南京', '其他'],
                datasets: [
                    {
                        label: '新生人数',
                        fillColor: 'rgb(122,134,34)',
                        data: [234, 278, 270, 190, 230]
                    },
                    {
                        label: '男生人数',
                        fillColor: 'rgb(51,0,255)',
                        data: [134, 111, 90, 100, 130]
                    },
                    {
                        label: '女生人数',
                        fillColor: 'rgb(255,0,77)',
                        data: [100, 167, 180, 90, 100]
                    }
                ]
            }
        };
    },
    components: {
        Schart
    },
    computed: {
        role() {
            return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
    created() {
        this.getSexCount();
        this.getCount();
        this.eight();
    },
    methods: {
        async getSexCount() {
            const res = await this.getJSON(`/student/countsex`);
            this.wuman_count = res.data[0].num;
            this.man_count = res.data[1].num;
        },
        // 报名总人数
        async getCount() {
            const res = await this.getJSON(`/student/countperson`);
            this.user_count = res.data.count;
        },
        async eight() {
            const res = await this.getJSON(`/student/eighteento`);
            this.eight_count = res.data.count;
        }
    }
};
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 40px;
    margin-top: 40px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
</style>
